package com.shangcheng.server.controller;


import com.shangcheng.model.domain.PmsBrand;
import com.shangcheng.model.vo.PageResult;
import com.shangcheng.model.vo.result.Result;
import com.shangcheng.server.service.PmsBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/brand")
public class PmsBrandController {
    @Autowired
    private PmsBrandService pmsBrandService;

    //添加品牌
    @PostMapping("/create")
    public ResponseEntity add(@RequestBody PmsBrand brand){

        pmsBrandService.insert(brand);
        return ResponseEntity.ok(new Result(200,null,null));
    }
    //批量删除品牌
    @PostMapping("/delete/batch")
    public ResponseEntity deleteBatch( Integer[] ids){
        pmsBrandService.deleteByBatch(ids);
        return ResponseEntity.ok(new Result(200,null,null));
    }
    //删除品牌
    @GetMapping("/delete/{id}")
    public ResponseEntity deleteById(@PathVariable Integer id){
        pmsBrandService.deleteById(id);
        return ResponseEntity.ok(new Result(200,null,null));
    }
    //根据品牌名称分页获取品牌列表
    @GetMapping("/list")
    public ResponseEntity list(@RequestParam(defaultValue = "1") Integer pageNum,
                               @RequestParam(defaultValue = "5") Integer pageSize,String keyword){
        PageResult pageResult = pmsBrandService.findPage(pageNum,pageSize,keyword);
        return ResponseEntity.ok(new Result(200,pageResult,null));
    }
    //获取全部品牌列表
    @GetMapping("/listAll")
    public ResponseEntity getAll(){
        List<PmsBrand> pageResult = pmsBrandService.findAll();
        return ResponseEntity.ok(new Result(200,pageResult,null));
    }
    //批量更新厂家制造商状态
    @PostMapping("/update/factoryStatus")
    public ResponseEntity updateFactoryStatus( Integer[] ids,Integer factoryStatus){
        pmsBrandService.updateFactoryStatus(ids,factoryStatus);
        return ResponseEntity.ok(new Result(200,null,null));
    }
    //更新品牌
    @PostMapping("/update/{id}")
    public ResponseEntity updateById(@PathVariable Integer id,@RequestBody PmsBrand pmsBrand){
        pmsBrand.setId(Long.valueOf(id));
        pmsBrandService.updateBrand(pmsBrand);
        return ResponseEntity.ok(new Result(200,null,null));
    }
    //根据编号查询品牌信息
    @GetMapping("/{id}")
    public ResponseEntity updateById(@PathVariable Integer id){
        PmsBrand pmsBrand=pmsBrandService.findBrandById(id);
        return ResponseEntity.ok(new Result(200,pmsBrand,null));
    }

    //批量更新显示状态
    @PostMapping("/update/showStatus")
    public ResponseEntity showStatus( Integer[] ids,Integer showStatus){
        pmsBrandService.showStatus(ids,showStatus);
        return ResponseEntity.ok(new Result(200,null,null));
    }

}
